<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>销假申请</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/resources/css/public.css" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend style="color: #35c6d3;font-weight:bold;">销假申请</legend>
</fieldset>
<div class="layuimini-container" style="padding-left:50px;padding-right: 50px;">
    <div class="layuimini-main">
        <!-- 数据表格开始 -->
        <table class="layui-hide" id="leaveTable" lay-filter="leaveTableFilter"></table>
        <div id="currentTableBar" style="display: none;">
            <button type="button" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="backout">销假</button>
        </div>
        <!-- 数据表格结束 -->
    </div>
</div>

<script type="text/javascript" src="/resources/layui/layui.js" charset="utf-8"></script>

<script type="text/javascript">
    layui.use(['jquery', 'form', 'table', 'layer'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layer = layui.layer;

        //加载数据
        var tableIns = table.render({
            elem: '#leaveTable',
            url: '/leave/loadAllLeaveByStatus?status=2',
            // toolbar: '#toolbarDemo',
            cols: [
                [
                    {field: 'id', title: 'ID', sort: true},
                    {field: 'sid', title: '学号', align: 'center'},
                    {field: 'studentname', title: '姓名', align: 'center'},
                    {field: 'grade', title: '级别', align: 'center'},
                    {field: 'classes', title: '班级', align: "center"},
                    {field: 'createtime', title: '请假时间', align: "center"},
                    {
                        field: 'status', title: '状态', align: 'center', templet: function (data) {
                                return '<span class="ebe-badge ebe-tag-success">' + '未销假';
                        }
                    },
                    {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line',
            done: function (res, curr, count) { //处理删除某一页最后一条数据的BUG
                if (res.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: (curr - 1)
                        }
                    });
                }
            }
        });

        //监听行工具条的事件
        table.on("tool(leaveTableFilter)", function (obj) {
            var data = obj.data; //获得当前行数据
            switch (obj.event) {
                case 'backout':
                    backoutLeave(data);
                    break;
            }
            ;
        });

        //销假
        function backoutLeave(data) {
            layer.confirm('你确定要销假吗?', {icon: 3, title: '提示'}, function (index) {
                $.post("/leave/backoutLeave", {id: data.id}, function (res) {
                    if (res.code == 200) {
                        tableIns.reload();
                    }
                    layer.msg(res.msg);
                })
                layer.close(index);
            });
        }
    });
</script>

</body>
</html>